/*
 * @(#)InvocationException.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.exception;

import java.util.Map;

import com.nhncorp.usf.core.call.Fault;
import com.nhncorp.usf.core.util.ErrorUtil;

/**
 * @author Web Platform Development Team
 */
public class InvocationException extends Exception {
    private static final long serialVersionUID = 6264890990476002589L;

    protected String code;
    protected String message;
    protected Map<String, Object> detail;

    /**
     * Gets the code.
     *
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @see java.lang.Throwable#getMessage()
     * {@inheritDoc}
     */
    public String getMessage() {
        return message;
    }

    /**
     * Gets the exception data.
     *
     * @return the exception data
     */
    public Map<String, Object> getDetail() {
        return detail;
    }

    /**
     * Instantiates a new invocation exception.
     *
     * @param code    the code
     * @param message the message
     */
    public InvocationException(String code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * Instantiates a new invocation exception.
     *
     * @param fault the fault
     */
    @SuppressWarnings("unchecked")
    public InvocationException(Fault fault) {
        this(fault.getCode(), fault.getMessage());
        this.detail = (Map)fault.getDetail();
        String aNew = ErrorUtil.getProperties(fault.getMessage()).get("code");

        if (aNew != null) {
            this.code = aNew;
        }
    }

    /**
     * Gets the.
     *
     * @param name the name
     * @return the object
     */
    public Object get(String name) {
        return (detail == null) ? null : detail.get(name);
    }
}
